package io.renren.modules.peoplemanage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mysql.cj.util.StringUtils;
import io.renren.common.utils.MapUtils;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.peoplemanage.dao.SysStudentDao;
import io.renren.modules.peoplemanage.entity.SysStudentEntity;
import io.renren.modules.peoplemanage.service.SysStudentService;
import org.springframework.stereotype.Service;

import java.util.Map;


/**
 *
 *
 * @author kiven
 * @email 2213593288@qq.com
 * @date 2020-09-04 16:50:44
 */
@Service("sysStudentService")
public class SysStudentServiceImpl extends ServiceImpl<SysStudentDao, SysStudentEntity> implements SysStudentService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SysStudentEntity> page = this.page(
                new Query<SysStudentEntity>().getPage(params),
                new QueryWrapper<SysStudentEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils getStudentList(Map<String, Object> queryParams) {
        String className = (String)queryParams.get("className");
        String gender = (String)queryParams.get("gender");
        String studentName = (String)queryParams.get("studentName");
        String card = (String)queryParams.get("card");
        String page1 = (Integer)queryParams.get("page")+"";
        String limit = (Integer)queryParams.get("limit")+"";

        /*分页 or是或者, StringUtils.isNullOrEmpty是判断null或者"",然后就不会拼接字符串了*/
        MapUtils params = new MapUtils();
        QueryWrapper<SysStudentEntity> wrapper = new QueryWrapper<SysStudentEntity>();
        wrapper.eq(!StringUtils.isNullOrEmpty(className),"class_name",className)
                .eq(!StringUtils.isNullOrEmpty(gender),"gender",gender)
                .like(!StringUtils.isNullOrEmpty(studentName),"student_name",studentName)
                .eq(!StringUtils.isNullOrEmpty(card),"card1",card).or()
                .eq(!StringUtils.isNullOrEmpty(card),"card2",card).or()
                .eq(!StringUtils.isNullOrEmpty(card),"card3",card).or()
                .eq(!StringUtils.isNullOrEmpty(card),"card4",card).or().orderByDesc("update_time");

        params.put("page",page1).put("limit",limit);
        IPage<SysStudentEntity> page = this.page(
                new Query<SysStudentEntity>().getPage(params),wrapper);
        System.out.println(page.getRecords());
        return new PageUtils(page);
    }

}